package org.autumn.lock;

import java.util.concurrent.locks.ReentrantLock;

/**
 * 可重入
 */
public class ReentrantLockClass {

    static ReentrantLock lock = new ReentrantLock();

    public static void main(String[] args) {
        lock.lock();  // block until condition holds
        try {
            // ... method body
            System.out.println(1);
            m1();
        } finally {
            lock.unlock();
        }
    }

    private static void m1() {
        lock.lock();  // block until condition holds
        try {
            // ... method body
            System.out.println(2);
        } finally {
            lock.unlock();
        }
    }
}
